package logic

import (
	"context"
	"github.com/pkg/errors"
	"mall/app/product/cmd/rpc/pb"
	"mall/common/xerr"

	"mall/app/product/cmd/api/internal/svc"
	"mall/app/product/cmd/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateBrandLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUpdateBrandLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateBrandLogic {
	return &UpdateBrandLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdateBrandLogic) UpdateBrand(req *types.Brand) error {
	_, err := l.svcCtx.ProductRpc.UpdateBrand(l.ctx, &pb.UpdateBrandReq{
		BrandId:     req.BrandId,
		Name:        req.Name,
		Descript:    req.Descript,
		FirstLetter: req.FirstLetter,
		Sort:        req.Sort,
		ShowStatus:  req.ShowStatus,
		Logo:        req.Logo,
	})
	if err != nil {
		return errors.Wrapf(xerr.NewErrorWithMsg("更新品牌失败"), "req: %+v err: %v", req, err)
	}
	return nil
}
